<template>
  <a-card :bordered="false" :style="{ marginTop: '12px',height:'513px' }">
    <span slot="title"> <a-icon type="tags" style="color:#3393FC;margin-right: 5px" theme="filled"/>近期邮件</span>
    <a slot="extra" @click="loadMore('/modules/eoa/email/EoaCmsEmailList')">更多</a>
    <template>
      <a-table
        ref="table"
        rowKey="id"
        :columns="columns"
        :dataSource="emailData"
        :pagination="false"
        :loading="emailLoading"
        :customRow="clickThenCheck">
        <span slot="emailTitle" slot-scope="text">
          <j-ellipsis :value="text" :length="12"/>
        </span>
      </a-table>
    </template>
    <eoaEmailIn-modal ref="eoaEmailInModal" @ok="handOk" @reply="handleReply"></eoaEmailIn-modal>
  </a-card>
</template>

<script>
  import JEllipsis from '@/components/jeecg/JEllipsis'
  import EoaEmailInModal from '../../email/modals/EoaEmailInModal'
  import store from '@/store'
  import { getAction } from '@/api/manage'

  export default {
    name: 'EoaCmsEmail',
    components: {
      JEllipsis,
      EoaEmailInModal
    },
    data () {
      return {
        emailLoading: false,
        emailData: [],
        columns:[
          {
            title: '标题',
            dataIndex: 'title',
            align:'center',
            scopedSlots: { customRender: 'emailTitle' }
          },
          {
            title: '状态',
            align:'center',
            dataIndex: 'readFlagText'
          },
          {
            title: '发件人',
            align:'center',
            dataIndex: 'senderId_dictText',
          },  {
            title: '日期',
            align:'center',
            dataIndex: 'sendTime'
          }
        ]
      }
    },
    created() {
      this.getEmailList();
    },
    methods: {
      handOk(){
        console.log("===handOk===");
        this.getEmailList();
      },
      handleReply(record){
        this.$router.push({ path: '/modules/eoa/email/EoaCmsEmailList',query:{type:'process',rec:record}})
      },
      getEmailList(){
        this.emailLoading=true
        this.emailData=[];
        var param=[];
        param.pageNo =1;
        param.pageSize = 5;
        param.userId=store.getters.userInfo.id;
        param.status="0";
        getAction("/eoa/email/eoaMailboxInfo/sendList",param).then((res) =>{
          if(res.success){
            var emailData=res.result.records
            if(emailData){
              for(let i=0;i<emailData.length;i++){
                var readFlag=emailData[i].readFlag;
                var readFlagText="";
                if(readFlag==="0"){
                  readFlagText="未读"
                }else{
                  readFlagText="已读";
                }
                emailData[i].readFlagText=readFlagText;
                emailData[i].sendTime=emailData[i].sendTime.substring(0,10);
              }
              this.emailData=emailData;
              this.emailLoading=false
            }
          }
        })
      },
      loadMore(path){
        let query={}
        query.type="inbox"
        this.$router.push({ path: path,query:query})
      },
      clickThenCheck(record) {
        return {
          on: {
            click: () => {
              this.handClick(record)
            }
          }
        }
      },
      handClick(data){
        this.$refs.eoaEmailInModal.view(data);

      },
    }
  }
</script>

<style scoped>

</style>